//
//  SCRetweetView.swift
//  weibo
//
//  Created by 阿城 on 15/12/9.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit
import SnapKit

class SCRetweetView: UIView {

    var statusViewModel: SCStatusViewModel?{
        didSet{
            contentLab.attributedText = statusViewModel?.retweetAttributeStr
            contentLab.linkResults = statusViewModel?.retweetMatchResult
            picView.picsUrl = statusViewModel?.statusMod?.retweeted_status?.pic_urls
            
            //更换约束
            if picView.picsUrl?.count != 0 {
                picView.hidden = false
                viewBottomConstraint?.uninstall()
                self.snp_updateConstraints{ (make) -> Void in
                    viewBottomConstraint = make.bottom.equalTo(picView).offset(kMargin).constraint
                }
            }else{
                picView.hidden = true
                viewBottomConstraint?.uninstall()
                self.snp_updateConstraints{ (make) -> Void in
                    viewBottomConstraint = make.bottom.equalTo(contentLab).offset(kMargin).constraint
                }
            }
        }
    }
    
    private lazy var contentLab:SCContentLabel = SCContentLabel(titleText: "XXXXX", color: UIColor.darkGrayColor(), fontSize: kStatusFont)
    private lazy var picView: SCPictureView = SCPictureView()
    
    //记录约束
    private var viewBottomConstraint: Constraint?
    
    private func setupUI(){
        addSubview(contentLab)
        addSubview(picView)
        contentLab.numberOfLines = 0
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        contentLab.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(kMargin)
            make.top.equalTo(self).offset(kMargin)
            make.trailing.equalTo(self).offset(-kMargin)
        }
        picView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLab.snp_bottom).offset(kMargin)
            make.leading.equalTo(contentLab)
        }
        self.snp_makeConstraints { (make) -> Void in
            viewBottomConstraint = make.bottom.equalTo(picView).offset(kMargin).constraint
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
